<?php


namespace App\Models;

use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * 镖师
 * Class Escort
 *
 * @package App\Models
 * @property int $id
 * @property int|null $uid
 * @property int|null $school_id 用户id
 * @property string|null $realname 姓名
 * @property string|null $phone 手机号
 * @property string|null $material
 * @property string|null $address
 * @property string|null $pending_money 待结算金额
 * @property float|null $balance_money 余额
 * @property string|null $withdraw_money 提现金额
 * @property int|null $is_outside_escort 0不允许校外配送  1允许
 * @property int|null $status 1正常 0申请中
 * @property string|null $reason
 * @property \Illuminate\Support\Carbon|null $created_at  创建时间
 * @property \Illuminate\Support\Carbon|null $updated_at 更新时间
 * @property int|null $deleted_at
 * @method static \Illuminate\Database\Eloquent\Builder|Escort newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|Escort newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|Escort query()
 * @method static \Illuminate\Database\Eloquent\Builder|Escort whereAddress($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Escort whereBalanceMoney($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Escort whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Escort whereDeletedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Escort whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Escort whereIsOutsideEscort($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Escort whereMaterial($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Escort wherePendingMoney($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Escort wherePhone($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Escort whereRealname($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Escort whereReason($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Escort whereSchoolId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Escort whereStatus($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Escort whereUid($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Escort whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Escort whereWithdrawMoney($value)
 * @mixin \Eloquent
 * @property string|null $avatar
 * @property-read \App\Models\User|null $user
 * @method static \Illuminate\Database\Eloquent\Builder|Escort whereAvatar($value)
 * @method static \Illuminate\Database\Query\Builder|Escort onlyTrashed()
 * @method static \Illuminate\Database\Query\Builder|Escort withTrashed()
 * @method static \Illuminate\Database\Query\Builder|Escort withoutTrashed()
 * @property int|null $role 1：镖师 2：镖头
 * @property int|null $leader 镖头
 * @method static \Illuminate\Database\Eloquent\Builder|Escort whereLeader($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Escort whereRole($value)
 * @property-read mixed $status_text
 * @property-read mixed $role_text
 * @property-read \App\Models\User|null $leaderInfo
 */
class Escort extends BaseModel
{
    use SoftDeletes;
    protected $guarded = [];
    protected $dateFormat = 'U';
    protected $casts = [
        'material'=>'json'
    ];
    protected $appends = ['status_text', 'role_text'];

    public static $statusEnum = [
        '0' => '审核中',
        '1' => '开工',
        '2' => '休息'
    ];
    public static $roleEnum = [
        '1' => '镖师',
        '2' => '镖头'
    ];

    public function leaderInfo()
    {
        return $this->hasOne(User::class, 'id', 'leader');
    }


    public function user()
    {
        return $this->belongsTo(User::class, 'uid', 'id');
    }

    public function getAvatarAttribute($value)
    {
        if(!$value){
            return asset('/static/img/escort.png');
        }
        return $value;
    }

    public function getStatusTextAttribute()
    {
        return self::$statusEnum[$this->status];
    }

    public function getRoleTextAttribute()
    {
        return self::$roleEnum[$this->role];
    }
}